package com.yl.common.control

import com.yl.common.ErrorCode

/**
 *向前端返回数据的内容.
 */
data class ResponseBody(
	val code: Int,
	val data: Any?,
	val msg:String?
){

	fun bodyIsError():Boolean{
		return code != ErrorCode.SUCCESS.code
	}
}

fun returnSuccess(data: Any? = null): ResponseBody {
	return ResponseBody(
		code = ErrorCode.SUCCESS.code,
		data = data,
		msg = ErrorCode.SUCCESS.hint,
	)
}


fun returnError(code: ErrorCode, msg: String? = null): ResponseBody {
	return ResponseBody(
		code = code.code,
		data = null,
		msg = msg?:code.hint,
	)
}
